
var netUtil = require('/../../utils/netUtil.js')
var util = require('/../../utils/util.js')
var app = getApp();

Page({
  data:{
 		saveOrderDetail : null,
 		voucherId : null
  },
  onLoad:function(options){
  	
  	//存查单订单号
  	var voucherId = options.voucherId;
  	
  	if(voucherId != undefined && voucherId != null) {
  		this.setData({
  			voucherId : voucherId
  		});
  	}
  	
  	app.getUserOpedId(this.querySaveOrderDetailArray);
  	
  },
  onReady:function(){
  
  },
  onShow:function(){
    
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },

  onUnload:function(){
    // 页面关闭

  },
  
  querySaveOrderDetailArray : function() {
  	var that = this;
  	var params = {
  		method : 'wechat.wisen.in.inItems.query',
  		openId : app.globalData.userInfo.openid,
  		data : {
  			voucherId : that.data.voucherId
  		}
  	};
  	
  	netUtil.buildRequest(that,'/wisen/api/wechat/ret',params,{
  		onPre: function() {
				netUtil.showLoadingDialog(that);
			},
			onSuccess : function(resp) {
			 	
			 	netUtil.hideLoadingDialog(that);
			 
				//如果请求成功
				if(resp.ret == app.globalData.respSuccessCode) {
					
					var saveOrderDetail = resp.data;
							
					saveOrderDetail.getTime = util.formatOrderDetailTime(saveOrderDetail.getTime);
					saveOrderDetail.updateTime = util.formatOrderDetailTime(saveOrderDetail.updateTime);
					saveOrderDetail.endTime = util.formatOrderDetailTime(saveOrderDetail.endTime);
					
					//为返回的数据这只 套餐的值(月，季，年) ===== start
					var comboArray = app.globalData.comboArray;
					for(var i=0;i<saveOrderDetail.items.length;i++) {
						for(var j=0;j<comboArray.length;j++) {
							if(comboArray[j].comboKey == saveOrderDetail.items[i].combo) {
								saveOrderDetail.items[i].comboValue = comboArray[j].comboValue;
							}
						}
					}
						//为返回的数据这只 套餐的值(月，季，年) ===== end
					
					that.setData({
						saveOrderDetail : saveOrderDetail
					});
				
				} else {
						
						if(resp.message != undefined && resp.message != null && resp.message != '') {
 							netUtil.showAlertDialog("提示", resp.message, false, "确定", null, null);
 						} else {
 							netUtil.showAlertDialog("提示", "网络请求失败", false, "确定", null, null);
 						}
				}				
			},
			onError: function(msgCanShow, code, hiddenMsg) {
        console.log("fail");
				netUtil.hideLoadingDialog(that);
				netUtil.showAlertDialog("提示", msgCanShow, false, "确定", null, null);
			}
  		
  	}).send();
  	
  },
  
  //跳转到村查单详情修改页面
  toSaveOrderUpdatePage : function(e) {	
  		wx.navigateTo({
 				 url: '/pages/save-order-update/save-order-update?voucherId=' + this.data.voucherId
			})
  }
  

})